package com.tms.firtsp.controller;

import com.tms.firtsp.entities.Student;
import com.tms.firtsp.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping(value = "/student2")
public class Student2Controller {

    @Autowired
    StudentService studentService;

    @PostMapping
    public Student add(Student student){

        student=studentService.save(student);

        log.info("student id:{}",student.getId());

        return student;
    }


    @DeleteMapping("/{id}")
    public  boolean delete(@PathVariable  Integer id){

        studentService.delete(id);

        return  true;
    }

    @PutMapping
    public  Student update(Student student){
        student=studentService.update(student);
        return student;
    }

    @GetMapping("/{id}")
    public Student getById(@PathVariable  Integer id){

        return studentService.findOne(id);

    }

    @GetMapping
    public List<Student> getAll(){

        return studentService.findAll();

    }

}
